<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
session_start();
error_reporting(0);

class Login extends CI_Controller {

    var $data = array();

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('session');
        #$this->load->library('common');
        $this->load->model('Login_model', 'login', TRUE);
        $this->data['post'] = $this->input->post();
    }

    /* Load default view for login. */

    public function index() {
        $this->load->view("login");
    }

    /* Check user & password by LDAP */

    public function checkLogin() {
        echo $this->login->checkAuth2(trim($this->data['post']['username']), trim($this->data['post']['password']), trim($this->data['post']['corporate']));
    }

    /* Load coporation by user,if user is set approve permission. */

    public function getCorp() {
        $username = $this->data['post']['username'];
        if ($username):
            $this->data['result'] = $this->login->get_corp_user(trim($username));
            $this->data['trow'] = count($this->data['result']);
            $this->data['list'] = NULL;
            echo (int) ($this->data['trow']) > 1 ? "<option value=''>--��س����͡--</option>" : NULL;
            for ($this->data['loop'] = 0; $this->data['loop'] < $this->data['trow']; $this->data['loop']++):
                echo "<option value='" . $this->data['result'][$this->data['loop']]['FCCODE'] . "'>" . $this->data['result'][$this->data['loop']]['FCNAME'] . "</option>";
            endfor;
        endif;
    }

    /* Set logout of CMIS System */

    public function logout() {
        $this->session->unset_userdata('username');
        $this->session->unset_userdata('logged_in');
        $this->session->unset_userdata('corperate');
        session_destroy();
        redirect('');
    }

}

/* End of file login.php */
/* Location: ./application/controllers/login.php */